package com.clp.inflxudb.spring;

import org.springframework.beans.factory.FactoryBean;

class FluxTemplateFactoryBean implements FactoryBean<FluxTemplate> {
    private static Class clazz;
    private static String url;
    private static String token;
    private static FluxTemplate fluxTemplate;

    static void setFluxTemplate(String url, String token) {
        clazz = FluxTemplate.class;
        FluxTemplateFactoryBean.url = url;
        FluxTemplateFactoryBean.token = token;
        fluxTemplate = FluxTemplate.get(url, token);
    }

    static FluxTemplate getFluxTemplate() {
        if (fluxTemplate == null) throw new RuntimeException("还未初始化FluxTemplate！");
        return fluxTemplate;
    }

    @Override
    public FluxTemplate getObject() throws Exception {
        return fluxTemplate;
    }

    @Override
    public Class<?> getObjectType() {
        return clazz;
    }
}
